<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <script type="text/javascript" th:src="@{/js/jquery-1.8.3.min.js}"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html {
            height: 100%;
        }

        body {
            height: 100%;
        }

        .container {
            height: 100%;
            background-image: linear-gradient(to right, #a6c1ee, #fbc2eb);
        }

        .login-wrapper {
            background-color: #fff;
            width: 358px;
            height: 588px;
            border-radius: 15px;
            padding: 0 50px;
            position: relative;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
        }

        .header {
            font-size: 38px;
            font-weight: bold;
            text-align: center;
            line-height: 200px;
        }

        .input-item {
            display: block;
            width: 100%;
            margin-bottom: 20px;
            border: 0;
            padding: 10px;
            border-bottom: 1px solid rgb(128, 125, 125);
            font-size: 15px;
            outline: none;
        }

        .input-item::placeholder {
            text-transform: uppercase;
        }

        .btn {
            text-align: center;
            padding: 10px;
            width: 100%;
            margin-top: 40px;
            background-image: linear-gradient(to right, #a6c1ee, #fbc2eb);
            color: #fff;
        }

        .msg {
            text-align: center;
            line-height: 88px;
        }

        a {
            text-decoration-line: none;
            color: #abc1ee;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="login-wrapper">
        <div class="header">文兰航空/注册</div>
        <div class="form-wrapper">
            <form name="form" id="form" method="post">
                <input type="text" name="user.username" placeholder="请输入用户名" class="input-item" id="username">
                <input type="password" name="user.password" placeholder="密码" class="input-item" id="password">
                <input type="password" name="user.password" placeholder="重复密码" class="input-item" id="password2">
                <input id="loginhjj" type="button" value="注册" class="btn">
            </form>
        </div>
        <div class="msg">
            已有账户？
            <a href="/home/login">登录</a>
        </div>
    </div>
</div>
</body>
<script>
    $("#loginhjj").click(function () {
        if ($("#username").val() == '' || $("#password").val() == '' || $("#password2").val() == '') {
            alert("请输入完整信息");
            return;
        } else if ($("#password").val() != $("#password2").val()) {
            alert("两次密码不同");
            return;
        } else {
            $.ajax({
                type: "post",
                url: "/home/registered",
                data: {username: $("#username").val(), password: $("#password").val()},
                success: function (data) {
                    if (data == "true") {
                        alert("注册成功！");
                        window.location.href = "/home/login";
                    } else {
                        alert("用户名已存在");
                    }
                }
            });
        }
    });
</script>
</html>